<template>
  <div id="InboundDetails">
    <v-detail :detailData="inputData.detailData" :inputConfig="inputConfig" :rules="rules" @pop="setData" ref="input">
    </v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "InboundDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data() {
    return {
      rules: {
        hourstoholdlpn: [
          { validator: this.verify1, trigger: 'blur' },
        ],
        hourstoholdlot: [
          { validator: this.verify2, trigger: 'blur' },
        ],
        stacklimit: [
          { validator: this.verify1, trigger: 'blur' },
        ],
        maxpalletsperzone: [
          { validator: this.verify1, trigger: 'blur' },
        ],
        putawayloc: [
          { validator: this.Validate, trigger: 'blur' },
        ],
        qcloc: [
          { validator: this.Validate, trigger: 'blur' },
        ],
        returnsloc: [
          { validator: this.Validate, trigger: 'blur' },
        ],
        putawaystrategykey: [
          { required: true, trigger: 'change' },
        ]
      },
      whseidflag: true
    }
  },
  computed: {
    inputConfig() {
      return [
        [
          {
            type: "select",
            label: this.$t('config.receiptholdcode'),
            props: "receiptholdcode",
            options: this.getOptions('queryInventoryholdcodeDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.autoreleaselpnby'),
            props: "autoreleaselpnby",
            options: this.getOptions('querycodeLkup/HOLDRLSBY'),
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.hourstoholdlpn'),
            props: "hourstoholdlpn",
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.lotholdcode'),
            props: "lotholdcode",
            options: this.getOptions('queryInventoryholdcodeDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.autoreleaselotby'),
            props: "autoreleaselotby",
            options: this.getOptions('querycodeLkup/HOLDRLSBY'),
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.hourstoholdlot'),
            props: "hourstoholdlot",
            disabled: this.whseidflag
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.putawayStrategy'),
            props: "putawaystrategykey",
            options: this.getOptions('queryPutawaystrategyDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.putawayzone'),
            props: "putawayzone",
            options: this.getOptions('queryPutawayzoneDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.amstrategy'),
            props: "amstrategykey",
            options: this.getOptions('queryAmstrategyDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.putawayclass'),
            props: "putawayclass",
            options: this.getOptions('querycodeLkup/PACLASS'),
            disabled: this.whseidflag
          },
          {
            type: "table",
            label: this.$t('config.putawayloc'),
            props: "putawayloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.stacklimit'),
            props: "stacklimit",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.maxpalletsperzone'),
            props: "maxpalletsperzone",
            disabled: this.whseidflag
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.receiptvalidationtemplate'),
            props: "receiptvalidationtemplate",
            options: this.getOptions('queryReceiptvalidationDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "table",
            label: this.$t('config.qcloc'),
            props: "qcloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: `/queryLoc/`,
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.rfdefaultpack'),
            props: "rfdefaultpack",
            disabled: this.whseidflag
          },
          {
            type: "table",
            label: this.$t('config.returnsloc'),
            props: "returnsloc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions('queryPutawayzoneDropDown')
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCFLAG')
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions('querycodeLkup/LOCCATEGRY')
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleLot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions('querycodeLkup/YESNO')
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "input"
              }
            ],
            url: "/queryLoc/",
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.rfdefaultuom'),
            props: "rfdefaultuom",
            options: this.getOptions('queryFfdefaultuomDropDown/STD'),
            disabled: this.whseidflag
          },
        ],
        [
          {
            type: "select",
            label: this.$t('config.goodsType'),
            props: "skutype",
            options: this.getOptions('querycodeLkup/SKUTYPE'),
            disabled: this.whseidflag
          },
          {
            type: "checkbox",
            label: this.$t('config.manualsetuprequired'),
            props: "manualsetuprequired",
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.tempforasn'),
            props: "tempforasn",
            options: this.getOptions('querycodeLkup/YESNO'),
            disabled: this.whseidflag
          },
          {
            type: "checkbox",
            label: this.$t('config.rtxisexistscode'),
            props: "rtxisexistscode",
            disabled: this.whseidflag
          }
        ]
      ]
    }
  },
  methods: {
    verify(rule, value, callback) {
      if (value === '') {
        this.$message.error(this.$t('app.dataIsNotNull'))
        callback(new Error());
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te)
        if (!flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputNumberPlease'))
            this.inputData.detailData[rule.field] = 0
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputNumberPlease'))
          this.inputData.detailData[rule.field] = 0
          callback(new Error());
        }
      }
    },
    verify1(rule, value, callback) {
      if (value === '') {
        callback(new Error());
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te)
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
            this.inputData.detailData[rule.field] = 0
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
          this.inputData.detailData[rule.field] = 0
          callback(new Error());
        }
      }
    },
    verify2(rule, value, callback) {
      if (value === '') {
        callback(new Error());
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te)
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
          callback(new Error());
        }
      }
    },
    Validate(rule, value, callback) {
      if (value === '') {
        callback()
      } else {
        this.$api.get(`/queryLocByLocKey/${value}`).then(res => {
          
            if (!res.bean) {
              this.$message.error(this.$t('msg.msg7'))
              this.inputData.detailData[rule.field] = ''
              callback(new Error())
            } else {
              callback()
            }
          
        })
      }
    },
    setData(data, id, callback, listId) {
      if (listId == 1) {
        this.inputData.detailData.putawayloc = data.loc;
      } else if (listId == 2) {
        if (id == 1) {
          this.inputData.detailData.qcloc = data.loc;
        } else if (id == 3) {
          this.inputData.detailData.returnsloc = data.loc;
        }
      }
      callback(false);
    }
  },
  mounted() {
    if (this.$store.state.wms.toUpperCase().includes('WMWHSE')) {
      //仓库级
      this.whseidflag = false;
    }
  },
  components: {
    "v-detail": detail
  }
}
</script>

<style scoped>
</style>
